package com.world.cat.model.sys;


import com.world.cat.app.utils.qiniu.UploadUtil;
import com.world.cat.app.utils.qiniu.QiniuUtil;
import com.world.common.model.BaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Created by xinyu.qiu on 2017/2/25.
 * 用户私有文件表
 * 本地文件位置 :localFilePathPrefix+localFilePath
 * 七牛上文件的位置,qiniuFileBucket->的域名 + qiniuFilePath
 */
@Entity
@Table(name = "private_file")
public class PrivateFile extends BaseEntity {

    @Column(name = "username")
    private String username;//用户名
    @Column(name = "file_name")
    private String fileName;//文件名
    @Column(name = "mime_type")
    private String mimeType;//文件类型
    @Column(name = "local_file_path_prefix")
    private String localFilePathPrefix;//本地文件文件夹
    @Column(name = "local_file_path")
    private String localFilePath;//本地存储文件位置
    @Column(name = "qiniu_file_bucket")
    private String qiniuFileBucket;//七牛文件服务器容器
    @Column(name = "qiniu_file_path")
    private String qiniuFilePath;//七牛文件存储位置
    @Column(name = "file_size")
    private Integer fileSize;//文件大小,字节
    @Column(name = "file_hash")
    private String fileHash;//文件hash
    @Column(name = "file_key")
    private String fileKey;//文件的一个随机码

    //扩增字段
    @Transient
    private String downLoadUrl;//内部下载地址相对路径 ,相对路径可以用于存到别的表里,使用的时候,
    @Transient
    private String downLoadFullUrl;//内部下载地址绝对路径
    @Transient
    private String appDownLoadFullUrl;//给APP端使用的下载地址

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }


    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }


    public String getLocalFilePathPrefix() {
        return localFilePathPrefix;
    }

    public void setLocalFilePathPrefix(String localFilePathPrefix) {
        this.localFilePathPrefix = localFilePathPrefix;
    }


    public String getLocalFilePath() {
        return localFilePath;
    }

    public void setLocalFilePath(String localFilePath) {
        this.localFilePath = localFilePath;
    }


    public String getQiniuFileBucket() {
        return qiniuFileBucket;
    }

    public void setQiniuFileBucket(String qiniuFileBucket) {
        this.qiniuFileBucket = qiniuFileBucket;
    }


    public String getQiniuFilePath() {
        return qiniuFilePath;
    }

    public void setQiniuFilePath(String qiniuFilePath) {
        this.qiniuFilePath = qiniuFilePath;
    }


    public Integer getFileSize() {
        return fileSize;
    }

    public void setFileSize(Integer fileSize) {
        this.fileSize = fileSize;
    }


    public String getFileHash() {
        return fileHash;
    }

    public void setFileHash(String fileHash) {
        this.fileHash = fileHash;
    }


    public String getFileKey() {
        return fileKey;
    }

    public void setFileKey(String fileKey) {
        this.fileKey = fileKey;
    }

    public String getDownLoadUrl() {
        return UploadUtil.getRelativeDownLoadUrlByFileKey(this.getFileKey());
    }

    public void setDownLoadUrl(String downLoadUrl) {
        this.downLoadUrl = downLoadUrl;
    }

    public String getDownLoadFullUrl() {
        return UploadUtil.getFullDownLoadUrlByFileKey(this.getFileKey());
    }

    public void setDownLoadFullUrl(String downLoadFullUrl) {
        this.downLoadFullUrl = downLoadFullUrl;
    }

    public String getAppDownLoadFullUrl() {
        return QiniuUtil.getPrivateDownFileUrl(this.getQiniuFilePath(), true, null);
    }

    public void setAppDownLoadFullUrl(String appDownLoadFullUrl) {
        this.appDownLoadFullUrl = appDownLoadFullUrl;
    }
}
